import {createSlice} from "@reduxjs/toolkit";
import {constantRoutes} from "@/router";

export const routerSlice = createSlice({
    name: 'router',
    initialState: {
        routers: [], // 全部的路由信息
        addRoutes: [], // 后端加加入的路由
        definedRouter: [], // 后端返回的路由信息
        sidebarMenu: [] // 前端侧边栏菜单
    },
    reducers: {
        setRouters: (state, action) => {
            console.log('setRouters', action.payload)
            state.routers = action.payload
        },
        setSidebarMenu: (state, action) => {
            state.sidebarMenu = action.payload
        },
        setDefinedRouter: (state, action) => {
            state.definedRouter = action.payload
        }

    }
});


// 为每个 case reducer 函数生成 Action creators
export const {
    setRouters,
    setDefinedRouter
} = routerSlice.actions;

export default routerSlice.reducer;
